﻿using System;
using Caliburn.Micro;

namespace TimeKeeper.Results
{
    public class DialogResult : IResult
    {
        private readonly Screen _screen;

        public DialogResult(Screen screen)
        {
            _screen = screen;
        }

        public void Execute(ActionExecutionContext context)
        {
            bool? result = null;
            Caliburn.Micro.Execute.OnUIThread(() => result = IoC.Get<IWindowManager>().ShowDialog(_screen));
            OnComplete(new ResultCompletionEventArgs(){WasCancelled = !result.HasValue || result == false});
        }

        public event EventHandler<ResultCompletionEventArgs> Completed;

        protected void OnComplete(ResultCompletionEventArgs args)
        {
            if (Completed != null) Completed(this, args);
        }
    }
}
